<?php
/**
 * FileName: SystemSettingPaymentForm.php
 * Author: 790213952@qq.com
 * DateTime: 2024/8/15 下午5:03
 * SystemName: ym-admin
 *
 */

/**
 * FileName: SystemSettingBasicForm.php
 * Author: 790213952@qq.com
 * DateTime: 2024/8/7 下午12:34
 * SystemName: Ymtc
 *
 */


/**
 * FileName: SiteConfig.php
 * Author: Xiao Yao <790213952@qq.com>
 * DateTime: 2022-09-15 下午 02:23
 * Summary:
 */


namespace YmPhp\Admin\Http\Forms;


use YmPhp\Admin\Models\Setting as SystemSettingModel;
use YmPhp\Admin\Widgets\Form;
use Illuminate\Http\Request;

class SystemSettingPaymentForm extends Form
{
    /**
     * The form title.
     *
     * @var string
     */
    public $title = '基本设置';

    /**
     * Handle the form request.
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    public function handle(array $input)
    {
        (new SystemSettingModel())->saveConfig($input, 'system_payment');
        return $this->response()->success('保存成功')->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->tab(trans('setting.payment.wechat'), function () {
            $this->radio('is_wechat', trans('setting.payment.is_wechat'))->when(1, function (Form $form) {
                $this->text('wechat_appid', trans('setting.payment.wechat_appid'));
                $this->text('wechat_appsecert', trans('setting.payment.wechat_appsecert'));
                $this->text('wechat_mchid', trans('setting.payment.wechat_mchid'));
                $this->text('wechat_key', trans('setting.payment.wechat_key'))->help(trans('setting.payment.wechat_key_msg'));
                $this->textarea('wechat_v3_pk', trans('setting.payment.wechat_v3_pk'))->help(trans('setting.payment.wechat_v3_pk_msg'));
                $this->textarea('wechat_v3_cf', trans('setting.payment.wechat_v3_cf'))->help(trans('setting.payment.wechat_v3_cf_msg'));

            })->options(['0' => trans('setting.basic.close'), '1' => trans('setting.basic.open')]);
        });
        $this->tab(trans('setting.payment.alipay'), function () {
            $this->radio('is_alipay', trans('setting.payment.is_alipay'))->when(1, function (Form $form) {
                $this->text('alipay_account', trans('setting.payment.alipay_account'));
                $this->text('alipay_appid', trans('setting.payment.alipay_appid'));
                $this->text('alipay_partner', trans('setting.payment.alipay_partner'));

                $this->textarea('alipay_public_key', trans('setting.payment.alipay_public_key'))->help(trans('setting.payment.alipay_public_key_msg'));
                $this->textarea('merchant_private_key', trans('setting.payment.merchant_private_key'))->help(trans('setting.payment.merchant_private_key_msg'));
            })->options(['0' => trans('setting.basic.close'), '1' => trans('setting.basic.open')]);
        });
        $this->tab(trans('setting.payment.shou_qian_ba'), function () {
            $this->radio('is_sqb', trans('setting.payment.is_sqb'))->when(1, function (Form $form) {
                $this->text('sqb_vendor_sn', trans('setting.payment.sqb_vendor_sn'));
                $this->text('sqb_vendor_key', trans('setting.payment.sqb_vendor_key'));
                $this->text('sqb_appid', trans('setting.payment.sqb_appid'));
                $this->text('sqb_code', trans('setting.payment.sqb_code'));
                $this->text('device_id', trans('setting.payment.device_id'));
                $this->textarea('terminal_sn', trans('setting.payment.terminal_sn'));
                $this->textarea('terminal_key', trans('setting.payment.terminal_key'));
            })->options(['0' => trans('setting.basic.close'), '1' => trans('setting.basic.open')]);

        });

    }

    /**
     * The data of the form.
     *
     * @return array $data
     */
    public function data()
    {
        $datas = SystemSettingModel::pluck('value', 'key');
        return $datas['system_payment'];
    }


}



